import java.util.LinkedList;
import java.util.Scanner;

interface IntegerStack{
    public Integer push(Integer item); //如item为null，则不入栈直接返回null。否则直接入栈，然后返回item。
    public Integer pop();              //出栈，如栈为空，则返回null。
    public Integer peek();             //获得栈顶元素，如栈顶为空，则返回null。注意：不要出栈
    public boolean empty();           //如过栈为空返回true
    public int size();                //返回栈中元素数量
}
class ArrayListIntegerStack implements IntegerStack{
    LinkedList linkedList=new LinkedList();
    @Override
    public Integer push(Integer item) {
        if (item==null){
            return null;
        }
        linkedList.push(item);
        return item;
    }

    @Override
    public Integer pop() {
        if (linkedList.size()==0){
            return null;
        }
        return (int)linkedList.pop();
    }

    @Override
    public Integer peek() {
        if (linkedList.size()==0){
            return null;
        }
        return (int)linkedList.peek();
    }

    @Override
    public boolean empty() {
        return linkedList.isEmpty();
    }

    @Override
    public int size() {
        return linkedList.size();
    }

    @Override
    public String toString() {
        String s="";
        s+="[";
        int i=linkedList.size();
        if (i!=0){
            i--;
            for (;i>0;i--){
                s+=linkedList.get(i)+", ";
            }
            s+=linkedList.get(i)+"]";
        }else {
            s+="]";
        }

        return  s;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int num=sc.nextInt();
        ArrayListIntegerStack arrayListIntegerStack = new ArrayListIntegerStack();
        for (int i=0;i<num;i++){
            int number=sc.nextInt();
            System.out.println(arrayListIntegerStack.push(number));
        }
        System.out.println(arrayListIntegerStack.peek()+","+arrayListIntegerStack.empty()+","+arrayListIntegerStack.size());
        System.out.println(arrayListIntegerStack.toString());
        int pop_num=sc.nextInt();
        for (int i=0;i<pop_num;i++){
            System.out.println(arrayListIntegerStack.pop());
        }
        System.out.println(arrayListIntegerStack.peek()+","+arrayListIntegerStack.empty()+","+arrayListIntegerStack.size());
        System.out.println(arrayListIntegerStack.toString());
    }
}
